
//
//  UIImage+Extension.swift
//  MyWeibo
//
//  Created by apple on 16/4/19.
//  Copyright © 2016年 Apengpeng. All rights reserved.
//

import UIKit

extension UIImage {
    
    // 是类方法, 有返回值
    class func shortScreenPicture() ->UIImage {
        
        let window = UIApplication.sharedApplication().keyWindow!
        // 开启上下文
        //<#T##opaque: Bool##Bool#>  是否透明
        UIGraphicsBeginImageContextWithOptions(window.bounds.size, false, UIScreen.mainScreen().scale)
        
        //把window 显示的内容画在上面
        window.drawViewHierarchyInRect(window.bounds, afterScreenUpdates: false)
        
        // 获取图片
        let image = UIGraphicsGetImageFromCurrentImageContext()
        
        // 关闭上下文
        UIGraphicsEndImageContext()
        return image
    }
}